<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2020/5/26} {16:34} 
 */

namespace libraries;


class BaseHook
{
    public function __construct()
    {
    }


    /**
     * @deprecated 未来可能被移除
     * desc：在控制器钩子中获取数id
     * author：wh
     * @param int $data
     * @return int|mixed
     * @throws \think\Exception
     */
    protected function getDataId($data = 0){
        $action = request()->action();
        $data_id = 0;//默认id
        if(!request()->isPost()) return $data_id;
        $update_sync_redis = sysconf('update_sync_redis'); //更新操作
        $add_sync_redis = sysconf('add_sync_redis');//新增操作
        //根据操作类型获取
        if($add_sync_redis && in_array($action, explode(',', $add_sync_redis))) {
            $data_id = $data;
        }
        if($update_sync_redis && in_array($action, explode(',', $update_sync_redis))){
            $data_id = input('id')?input('id'):input('data_id');
        }
        return $data_id;
    }
}